/*用户反馈 */
import React, { Component } from 'react'
import { connect } from 'react-redux'
import { Link } from 'react-router'
import { Button, Spin, Form, Input, Table, DatePicker, Modal, Select,message } from 'antd'
import moment from 'moment';
/* 引用接口文档路径 */
import {
  businessSelect,userFeedback
} from 'actions/business'
import {getbasetypefetch} from 'actions/common'
import '../../style/userControl.less'

const { MonthPicker, RangePicker } = DatePicker;
const FormItem = Form.Item
@Form.create({})
//abc
@connect(
  (state, props) => ({
    config: state.config,
    userInfoList: state.userInfoList,
  })
)
export default class app extends Component {
  constructor(props) {
    super(props)
    this.state = {
      list:"",//基础数据列表
      contentModal:false,//列表内容详情弹窗
      userList:"",//列表内容详情
      publishTime:"",
      auditList:[]
    }
    this.keyword={"feedbackPeople":"",'mobile':''};//搜索关键词
    this.currentNumber = 1;//当前页面
    this.pagesize = 10;//每页条数
  }
  componentDidMount() {
    this.selectList();
  }
  
  selectFn(){//点击搜索按钮
    this.keyword = {
      "feedbackPeople":this.props.form.getFieldValue('feedbackPeople'),
      "mobile":this.props.form.getFieldValue('mobile'),
    };
    this.currentNumber=1;
    this.selectList();
  }
  selectList(pageNumber){//查询列表
    const datajson = Object.assign({"start":pageNumber||1,"end":this.pagesize}, this.keyword);
    this.currentNumber = pageNumber||1;
    this.props.dispatch(businessSelect(
      datajson,
      (respose) => {
        this.setState({
          list: respose,
        })
    }))
  }
  manageFn(id,status){
    this.props.dispatch(userFeedback(
      {"id":id,"status":status},
      (respose) => {
        message.success(respose.respMsg);
            this.selectList(this.currentNumber);  
    }))
  }
  columns() {//表格标题
    return [
      {
        title: '反馈编号',
        key: 'code',
        dataIndex: 'code',
        width: '10%',
      },
      {
        title: '反馈内容',
        dataIndex: 'content',
        key: 'content',
        width: '30%',        
      },
      {
        title: '反馈时间',
        dataIndex: 'createTime',
        key: 'createTime',
        width: '10%',        
      },
      {
        title: '反馈人',
        dataIndex: 'feedbackPeople',
        key: 'feedbackPeople',
        width: '10%',
      },
      {
        title: '电话号码',
        dataIndex: 'mobile',
        key: 'mobile',
        width: '10%',
      },
      {
        title: '操作',
        width: '10%',
        dataIndex: 'status',
        key: 'status',
        render: (text, recordId, index) => 
        <div>
          {
            text==1?<Button type="primary" size="small" onClick={this.manageFn.bind(this,recordId.id,2)} style={{marginRight:"5px",marginBottom:"5px"}}>处理</Button>:'已处理'
          }
        </div>,
      }
    ]
  }
  


  render () {
    const {form } = this.props
    const { getFieldDecorator } = form    
    const respData = this.state.list.respData ? this.state.list.respData : [];//刷新页面调用接口数据赋值
    const joinList = this.state.userList.id ? this.state.userList :[];
    const dateFormat = 'YYYY/MM/DD';
    return (
      <div className="page">
        {/* 搜索条件筛选块 */}
        <div className="searcDiv">
          <Form onSubmit={this.selectFn.bind(this)} layout="inline">
            <FormItem label="反馈人">      
              {
                getFieldDecorator('feedbackPeople', {
                  rules: [{
                    required: false,
                  }],
                })(
                  <Input placeholder="请输入反馈人" size="default" style={{ width: '200px' }} />
                )
              }             
            </FormItem>
            <FormItem label="电话号码">      
              {
                getFieldDecorator('mobile', {
                  rules: [{
                    required: false,
                  }],
                })(
                  <Input placeholder="请输入关键字" size="default" style={{ width: '200px' }} />
                )
              }             
            </FormItem>
            <Button type="primary" onClick={this.selectFn.bind(this)}>搜索</Button>
          </Form>
        </div>
        {/*数据渲染列表*/}
        <Spin spinning={false}>
          <Table
            rowKey="id" 
            columns={this.columns()}//表格标题列
            dataSource={respData.resultData}
            pagination={{ total: respData.count, current:this.currentNumber,pageSize: this.pagesize, onChange: this.selectList.bind(this)}}
            scroll={{ y: true }}
            rowClassName={(record, index) => record.status == 1 ? 'tableRed' : ''} 
          />
        </Spin>
      </div>
    )
  }
}
